# Contributor: Ivan Tham <pickfire@riseup.net>
# Contributor: Francesco Colista <fcolista@alpinelinux.org>
# Maintainer: Francesco Colista <fcolista@alpinelinux.org>
pkgname=john
pkgver=1.9.0
_pkgrel=jumbo-1
pkgrel=7
pkgdesc="John the Ripper password cracker"
url="https://www.openwall.com/john"
arch="all !s390x !x86 !ppc64le"
license="GPL-2.0-or-later"
depends="nss"
options="!strip !check"  # needs config files in /usr which are not there during build/check
makedepends="libpcap-dev openssl-dev gmp-dev yasm-dev zlib-dev
libbz2 opencl-dev opencl-headers automake autoconf libtool"
subpackages="$pkgname-doc $pkgname-bash-completion $pkgname-zsh-completion"
source="https://www.openwall.com/john/k/john-$pkgver-$_pkgrel.tar.xz
	gcc11.patch
	john-pdf2john-path-fix.patch
	johntheripper-jumbo-1.9.0-opencl-fix.patch"
builddir="$srcdir"/$pkgname-$pkgver-$_pkgrel

prepare() {
	default_prepare

	cd src
	update_config_guess
	sed 's|$prefix/bin|/usr/lib/john|' -i configure.ac
	autoreconf -fiv
}

build() {
	CFLAGS="$CFLAGS -fcommon"
	cd src
	./configure \
		--prefix=/usr \
		--enable-pkg-config
	make -s clean
	make
}

check() {
	cd run
	./john --test
}

package() {
	cd src
	make DESTDIR="$pkgdir" install
	cd "$builddir"
	mkdir -p "$pkgdir"/usr/bin
	mkdir -p "$pkgdir"/usr/share/doc/$pkgname
	mkdir -p "$pkgdir"/usr/share/$pkgname/rules

	mv doc/extras "$pkgdir"/usr/share/doc/$pkgname
	install -Dm644 doc/* -t "$pkgdir"/usr/share/doc/$pkgname
	install -Dm644 run/rules/* -t "$pkgdir"/usr/share/$pkgname/rules
	install -Dm644 run/*.conf -t "$pkgdir"/usr/share/$pkgname/
	install -Dm644 run/*.chr -t "$pkgdir"/usr/share/$pkgname/
	install -Dm644 run/kernels/* -t "$pkgdir"/usr/share/$pkgname/kernels/
	install -Dm644 doc/LICENSE "$pkgdir"/usr/share/licenses/$pkgname/LICENSE
	rm "$pkgdir"/usr/share/doc/$pkgname/LICENSE*

	cd run
	find . -type f -executable | while read bin; do
		install -Dm755 $bin -t "$pkgdir"/usr/bin
	done

	find . -type l | while read link; do
		ln -s john "$pkgdir"/usr/bin/$link
	done

	install -Dm644 password.lst "$pkgdir"/usr/share/john/password.lst

	# completions in makefile are broken by design
	install -Dm644 john.bash_completion \
		"$pkgdir"/usr/share/bash-completion/completions/john
	install -Dm644 john.zsh_completion \
		"$pkgdir"/usr/share/zsh/site-functions/_john
}

sha512sums="
c5cb5dc739ee4c666f8479cdf10511fddc391b590c59f90c060d3ccd8449b794ac7b831a6d1f7553883892499e709a66578cfa4d62caef9b7e0a831eb827e808  john-1.9.0-jumbo-1.tar.xz
fe677bb22dd197245f2a0ff68f602e8f0571d46e1bc6bc7fb7d1ca7553fd7f78c632fa890f8510d80b3d28dc3d4a16087086362f45e7b99ba1fa804e4b7695bb  gcc11.patch
9a52195599378882badfc933c086096e6d10ee0db7a12050cf06e5a36b1bf7ed2d801f58ea1cd49e05debb83eb10d97d0c45a5790212cd316e1652c4a2a350d0  john-pdf2john-path-fix.patch
0001b41cbbd29f542d3ad9be383af66169e778464dcc9efb0b8febbdac757f97ec2a3c1f1068fa1c4a882de82824e661f1a25499009b2eeaed5931215c20108c  johntheripper-jumbo-1.9.0-opencl-fix.patch
"
